﻿#pragma once
#include "Class.g.h"
#include <winrt/Windows.ApplicationModel.AppService.h>
#include <winrt/Windows.ApplicationModel.Background.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Networking.Sockets.h>
#include <winrt/Windows.Networking.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Storage.Streams.h>
#include <winrt/Windows.Data.Json.h>
#include <winrt/Windows.System.Threading.h>
#include <chrono>

namespace winrt::Daemon::implementation
{
    struct Class : ClassT<Class>
    {
        Class() = default;

        winrt::Windows::ApplicationModel::Background::BackgroundTaskDeferral serviceDeferral{ nullptr };
        winrt::Windows::ApplicationModel::AppService::AppServiceDeferral deferral{ nullptr };
        winrt::Windows::ApplicationModel::AppService::AppServiceConnection connection{ nullptr };
        winrt::Windows::Networking::Sockets::StreamSocket socket{ nullptr };

        fire_and_forget HeartBeatAsync(winrt::Windows::System::Threading::ThreadPoolTimer timer);

        void Run(winrt::Windows::ApplicationModel::Background::IBackgroundTaskInstance const& taskInstance);
        void Destroy();
        void OnTaskCanceled(Windows::ApplicationModel::Background::IBackgroundTaskInstance const&, Windows::ApplicationModel::Background::BackgroundTaskCancellationReason const&);
        fire_and_forget OnRequestReceived(Windows::ApplicationModel::AppService::AppServiceConnection const&, Windows::ApplicationModel::AppService::AppServiceRequestReceivedEventArgs const& args);
    };
}
namespace winrt::Daemon::factory_implementation
{
    struct Class : ClassT<Class, implementation::Class>
    {
    };
}
